<?php
declare (strict_types=1);

namespace app\api\controller;

use think\facade\Env;

/**
 * @OA\Info(
 *     title="前台 API",
 *     version="1.0"
 * )
 */
class Swagger
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
        $path = __DIR__ . '/../../api';//你想要哪个文件夹下面的注释生成对应的API文档
        $swagger = \OpenApi\scan($path);
        //header('Content-Type: application/x-yaml');// var_dump($swagger);

        $swagger_json_path = PUBLIC_PATH . '/swagger-api.json';

        $res = file_put_contents($swagger_json_path, $swagger->toYaml());

        if ($res == true) {
            return redirect(Env::get('app.project_url') . '/swagger-ui/dist/api.html#/');
        }
    }

}
